package com.module.sysconfig.controller;

import java.io.IOException;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.module.sysconfig.service.IBmgzService;
import com.support.helper.AjaxHelper;
import com.support.jdbc.Page;
import com.support.util.StringUtils;
import com.support.web.ControllerSupport;

/**
 * 编码规则
 * @author mfj
 *
 */
@Controller
@Scope(value = "prototype")
@RequestMapping("/sysconfig")
public class BmgzController extends ControllerSupport 
{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private IBmgzService bmgzService;
	
	/**
	 * 新增 编码规则
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/saveBmgz")
	public void saveBmgz() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			bmgzService.saveBmgz(params);
			
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "保存 编码规则成功！"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.saveBmgz:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 删除 编码规则
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/deleteBmgz")
	public void deleteBmgz() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			String id = params.get("ID");
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.deleteBmgz(id);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除 编码规则成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.deleteBmgz:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 修改 编码规则
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/updateBmgz")
	public void updateBmgz() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.updateBmgz(params);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "修改 编码规则成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.updateBmgz:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 查询 编码规则
	 * @throws IOException
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("/bmgz/queryBmgz")
	public void queryBmgz() throws IOException
	{
		try
		{
			Page page = this.getParamsPage();
			
			page = bmgzService.queryBmgz(page);
			
			returnJSONView(AjaxHelper.toJSON(page, AjaxHelper.SUCCESS, "查询 编码规则成功！"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.queryBmgz:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	
	
	
	/**
	 * 新增 编码规则详情
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/saveGzxq")
	public void saveGzxq() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			bmgzService.saveGzxq(params);
			
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "保存 编码规则详情成功！"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.saveGzxq:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 删除 编码规则详情
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/deleteGzxq")
	public void deleteGzxq() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			String id = params.get("ID");
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.deleteGzxq(id);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除 编码规则详情成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.deleteGzxq:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 修改 编码规则详情
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/updateGzxq")
	public void updateGzxq() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.updateGzxq(params);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "修改 编码规则详情成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.updateGzxq:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 查询 编码规则详情
	 * @throws IOException
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("/bmgz/queryGzxq")
	public void queryGzxq() throws IOException
	{
		try
		{
			Page page = this.getParamsPage();
			
			page = bmgzService.queryGzxq(page);
			
			returnJSONView(AjaxHelper.toJSON(page, AjaxHelper.SUCCESS, "查询 编码规则详情成功！"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.queryGzxq:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	
	
	
	
	
	/**
	 * 保存 编码记录
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/saveBmjl")
	public void saveBmjl() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			bmgzService.saveBmjl(params);
			
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "新增 编码记录成功"));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.saveBmjl:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}

	/**
	 * 删除 编码记录
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/deleteBmjl")
	public void deleteBmjl() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			String id = params.get("ID");
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.deleteBmjl(id);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "删除 编码记录成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.deleteBmjl:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 修改 编码记录
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/updateBmjl")
	public void updateBmjl() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.updateBmjl(params);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "修改 编码记录成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.updateBmjl:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 查询 编码记录
	 * @throws IOException
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("/bmgz/queryBmjl")
	public void queryBmjl() throws IOException
	{
		try
		{
			Page page = this.getParamsPage();
			
			page = bmgzService.queryBmjl(page);
			
			returnJSONView(AjaxHelper.toJSON(page, AjaxHelper.SUCCESS, "查询 编码记录成功！"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.queryBmjl:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	
	
	
	/**
	 * 新增 编码规则关系
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/saveBmgzgx")
	public void saveBmgzgx() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			bmgzService.saveBmgzgx(params);
			
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "编码规则关系 保存成功！"));
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.saveBmgzgx:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 删除 编码规则关系
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/deleteBmgzgx")
	public void deleteBmgzgx() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			String id = params.get("ID");
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.deleteBmgzgx(id);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "编码规则关系删除成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.deleteBmgzgx:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	/**
	 * 修改 编码记录
	 * @throws IOException
	 */
	@RequestMapping("/bmgz/updateBmgzgx")
	public void updateBmgzgx() throws IOException
	{
		try
		{
			Map<String, String> params = this.getParamsMap();
			
			if(StringUtils.isNullOrEmpty(params.get("ID")))
			{
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "参数错误，ID未传"));
			}
			else
			{
				bmgzService.updateBmgzgx(params);
				
				returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.SUCCESS, "修改 编码规则关系成功！"));
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.updateBmjl:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
	
	/**
	 * 查询 编码规则关系
	 * @throws IOException
	 */
	@SuppressWarnings("rawtypes")
	@RequestMapping("/bmgz/queryBmgzgx")
	public void queryBmgzgx() throws IOException
	{
		try
		{
			Page page = this.getParamsPage();
			
			page = bmgzService.queryBmgzgxRecord(page);
			
			returnJSONView(AjaxHelper.toJSON(page, AjaxHelper.SUCCESS, "查询编规则关系成功"));
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			logger.error("BmgzController.deleteBmgzgx:", e);
			returnJSONView(AjaxHelper.toJSON(null, AjaxHelper.FAILURE, e.getMessage()));
		}
	}
}
